package cf.huzpsb.bcgod;

import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Command;

public class RegCMD extends Command {
    public RegCMD(String name, String permission, String... aliases) {
        super(name, permission, aliases);
    }

    public void execute(CommandSender sender, String[] args) {
        if (!(sender instanceof ProxiedPlayer)) {
            sender.sendMessage("§c后台不能使用此命令!");
        } else if (!((ProxiedPlayer) sender).getServer().getInfo().getName().equalsIgnoreCase(Main.login)) {
            sender.sendMessage("§c您已经登录!");
        } else if (Main.passcfg.contains(sender.getName())) {
            sender.sendMessage("§c您已经注册!");
        } else if (args.length != 2) {
            sender.sendMessage("§c命令参数错误!");
        } else if (!args[0].equals(args[1])) {
            sender.sendMessage("§c两次输入的密码不一致!");
        } else {
            Main.passcfg.set(sender.getName(), args[0]);
            ProxiedPlayer player = (ProxiedPlayer) sender;
            sender.sendMessage("§a注册成功,欢迎加入我们!");
            player.connect(Main.getInstance().getProxy().getServerInfo(Main.hub));
        }
    }
}
